import randomGap from './random-gap.ts';
import forceArray from './force-array.ts';
import json2json from './json2json.ts';
export default function dynamicBalance(input:any){
	var {targetPrice} = input;
	var balances = input.balances;
	var base = balances.base;
	var quote = balances.quote;
	var balancedPrice = base/quote;
  var gaps = randomGap(input, balancedPrice);
	var buy = {price:balancedPrice/gaps[0], money:(1-(1+1/gaps[0])/2)*base,amount:0};
	var sell = {price:balancedPrice*gaps[1], money:((1+gaps[1])/2-1)*base,amount:0};
  buy.amount = buy.money / buy.price;
  sell.amount = sell.money / sell.price;
	var futureAmount = forceArray(targetPrice).map(tPrice=>base * Math.sqrt(tPrice/balancedPrice));
	return {balancedPrice, gaps, buy, sell,futureAmount, input,L:(balances.base*balances.quote)**.5};

};
if (import.meta.main) json2json(dynamicBalance);
